//
//  EarlyRedemptionViewController.m
//  TenThousand
//
//  Created by 我的 on 16/7/18.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "EarlyRedemptionViewController.h"
#import "MyTouziViewController.h"
#import "DebtDetailsViewController.h"

@interface EarlyRedemptionViewController ()<UIAlertViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *xiangmumingcheng;//项目名称


@property (weak, nonatomic) IBOutlet UILabel *touzijine;//投资金额

@property (weak, nonatomic) IBOutlet UILabel *qixian;//期限

@property (weak, nonatomic) IBOutlet UILabel *kaishiriqi;//起息日

@property (weak, nonatomic) IBOutlet UILabel *biliweiyue;//违约金比例

@property (weak, nonatomic) IBOutlet UILabel *nianlilv;//年利率
@property (weak, nonatomic) IBOutlet UILabel *yujishou;//预计收益

@property (weak, nonatomic) IBOutlet UILabel *dangqianshou;//当前收益
@property (weak, nonatomic) IBOutlet UILabel *huikuanri;//回款日
@property (weak, nonatomic) IBOutlet UILabel *weiyue;//违约金
@end

@implementation EarlyRedemptionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createLeft:[UIImage imageNamed:@"ZHSZicon_03"] leftClick:^{
        [self.navigationController popViewControllerAnimated:YES];
    } right:nil rightClick:nil];
    
    
        self.navigationItem.title = @"提前赎回";
        _xiangmumingcheng.text = [NSString stringWithFormat:@"%@",_progrname];
        _touzijine.text = [NSString stringWithFormat:@"投资金额:%@",_amount];
        _qixian.text = [NSString stringWithFormat:@"期限:%@",_term];
        _kaishiriqi.text = [NSString stringWithFormat:@"起息日期:%@",_qixiriqi];
        _huikuanri.text = [NSString stringWithFormat:@"回款日期:%@",_adddata];
        _biliweiyue.text = [NSString stringWithFormat:@"违约金比例:%.2f%%",[_weiyuejinbili doubleValue]];
        
        _nianlilv.text = [NSString stringWithFormat:@"年利率:%@",_rate];
        _yujishou.text = [NSString stringWithFormat:@"预计收益:%@",_yujishouyi];
        _dangqianshou.text = [NSString stringWithFormat:@"当前收益:%@",_dangqianshouyi];
        _weiyue.text = [NSString stringWithFormat:@"违约金:%@",_weiyuejin];

    
    
    
}



- (IBAction)sureRed:(id)sender {
    
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否确认提前赎回?" message:@"温馨提示:赎回金额将会在1-7个工作日内到账,请及时查收!" delegate: nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
    alert.delegate = self;
    [alert show];
    
//     [self getAddredemption];
    
}

//跳转
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (buttonIndex == 0) {
        [self getAddredemption];
    }
 
}


//提前赎回
-(void)getAddredemption{
    
    /**
     *  BorrowListId  投资编号
     *  LoginName     用户编号
     */
    NSString *loginName = [[NSUserDefaults standardUserDefaults] objectForKey:@"LoginId"];
    
    NSDictionary *para = @{
                           @"BorrowListId":_BorrowListId,
                           @"LoginName":loginName
                           };
    
    
    [NetWorkManager requestWithType:HttpRequestTypePost withMethodName:@"Redemp.GetAddredemption" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        
        NSLog(@"%@",object);
        if ([object[@"Code"] isEqualToString:@"00000"]) {
         
            [ToastView showInfoWithStatus:object[@"Message"]];
            
            [self.navigationController popToRootViewControllerAnimated:YES];
            
        }else
                
        [ToastView showInfoWithStatus:object[@"Message"]];
        
    } withFailureBlock:^(NSError *error) {
        NSLog(@"%@",error);
        [ToastView showErrorWithStatus:@"网络请求失败"];
    } progress:nil];
}

//跳转到债权转让
- (IBAction)zhaiquan:(id)sender {
    DebtDetailsViewController *debt = [[DebtDetailsViewController alloc] init];
    
    debt.titleName = [NSString stringWithFormat:@"%@",_xiangmumingcheng.text];
    debt.BenjinStr = [NSString stringWithFormat:@"%@元",_amount];
    debt.ShouyiStr = [NSString stringWithFormat:@"%@元",_dangqianshouyi];
    debt.AllStr = [NSString stringWithFormat:@"%@元",_amount];

    
    [self.navigationController pushViewController:debt animated:YES];
    
    
}

@end
